import { defineStore  } from 'pinia'

export const useCounterStore = defineStore('counter', {
    // 这里必须用 arrow function , 才能通过类型校验
    state: () => {
        return {
            count: 0,
            /** @type {{ text: string, done: boolean }[]} */
            todos: [] as any[]
        }
    },
    getters: {
        doubleCount: (state) => state.count * 2
    },
    actions: {
        // 这里不能用 arrow function, this才能指向正确
        increment() {
            this.count++
            const todo = this.todos[0]
            console.log("🚀 ~ file: counter.ts:20 ~ increment ~ todo:", todo)
        }
    }
})